package com.philbeaudoin.server.core;

import java.text.Format;
import java.text.SimpleDateFormat;
import java.util.Date;

import com.google.inject.Inject;
import com.gwtplatform.dispatch.server.ExecutionContext;
import com.gwtplatform.dispatch.server.actionhandler.ActionHandler;
import com.gwtplatform.dispatch.shared.ActionException;
import com.philbeaudoin.shared.core.GetServerDate;
import com.philbeaudoin.shared.core.GetServerDateResult;

public class GetServerDateActionHandler implements
		ActionHandler<GetServerDate, GetServerDateResult> {

	@Inject
	public GetServerDateActionHandler() {
	}

	@Override
	public GetServerDateResult execute(GetServerDate action,
			ExecutionContext context) throws ActionException {
		Format formatter = new SimpleDateFormat("MMMM dd, yyyy");
		
		GetServerDateResult result = new GetServerDateResult(formatter.format(new Date()));
		
		return result;
	}

	@Override
	public void undo(GetServerDate action, GetServerDateResult result,
			ExecutionContext context) throws ActionException {
	}

	@Override
	public Class<GetServerDate> getActionType() {
		return GetServerDate.class;
	}
}
